/*
Rilego - An easy Images 2 E-Book converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

package it.kirys.rilego.engine;

import java.io.OutputStream;

/**
 * This class is a simple monitor for sending output messages to the console
 * @author Federico Improta
 */
public class EasyConsoleMonitor implements ICallBack{

	Engine engine;
	synchronized void print(String text){
		System.out.println(text);
	}
	@Override
	public void sendInfo(String message, EngineStatusInfo info) {
		StringBuilder sb = new StringBuilder();
		sb.append(message);
		print(sb.toString());
	}

	@Override
	public void logMessage(String message) {
		print(message);
	}

	@Override
	public void processEnded(boolean successfull) {
		print ("End");
	}


	public void run(OutputStream output){
		engine.setOutputStream(output);
		engine.start();
		engine.waitCompletition();
		print ("done");
	}//public void run()

	public EasyConsoleMonitor(Engine engine) {
		this.engine = engine;
		engine.addCallBack(this);
	}


}
